#include "mainwindow.h"
#include "ui_mainwindow.h"


MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    ui->stackedWidget->setCurrentWidget(ui->page1); //默认先显示链路规划界面


    // 显示qml部分
    QQuickView *mQuickView = new QQuickView();
    //注意，这里不能这样写，否则点击按钮修改QML属性的时候会崩溃，详细解释见链接：https://wenda.so.com/q/1609933915217582
    // QWidget *mQuickWidget = QWidget::createWindowContainer(mQuickView, this);
    mQuickWidget = QWidget::createWindowContainer(mQuickView, this);

    //设置被嵌入的窗口大小和位置
    mQuickWidget->move(300,100);
    mQuickWidget->resize(400,400);
    // mQuickWidget->setMinimumSize(80,30);
    mQuickWidget->show(); // 显示qml

    QQmlContext *mQuickContext = mQuickView->rootContext();// 用于与qml交互

    //设置qml控件quickWidgetWidth、quickWidgetHeigh属性
    mQuickContext->setContextProperty("quickWidgetWidth", 200);
    mQuickContext->setContextProperty("quickWidgetHeight", 200);

    mQuickView->setSource(QUrl("qrc:/point.qml"));



}

MainWindow::~MainWindow()
{
    delete ui;
}

// 目前这三个界面显示的是同一个QML（实时更新的）
void MainWindow::on_pushButton_clicked()
{
    ui->stackedWidget->setCurrentWidget(ui->page1);

    mQuickWidget->move(300,100);
    mQuickWidget->resize(400,400);

}


void MainWindow::on_pushButton_2_clicked()
{
    ui->stackedWidget->setCurrentWidget(ui->page2);

    mQuickWidget->move(280,100);
    mQuickWidget->resize(420,280); //长 宽

}


void MainWindow::on_pushButton_3_clicked()
{
    ui->stackedWidget->setCurrentWidget(ui->page3);

    mQuickWidget->move(340,100);
    mQuickWidget->resize(440,450); //长 宽

}

